:root {
    --bg-charcoal-dark: #121212;
    --bg-charcoal-light: #1e1e1e;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --neon-teal: #00f2ea;
    --neon-green: #39ff14;
    --accent-red: #ff4757;
    --accent-green: #2ed573;
    --font-family: 'Poppins', sans-serif;
    --border-radius-card: 12px;
    --border-radius-control: 8px;
    --transition-speed: 0.3s;
}

/* Loading Screen Styles */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: transparent; /* Changed to transparent, curtain effect handles background */
    overflow: hidden;
    /* Initially visible */
    visibility: visible;
    opacity: 1;
    transition: visibility 0s linear 0.8s, opacity 0.3s ease-out; /* Match curtain transition delay */
}

#loading-overlay::before,
#loading-overlay::after {
    content: '';
    position: absolute;
    top: 0;
    width: 50%;
    height: 100%;
    background-color: #000;
    z-index: 1;
    transition: transform 0.8s cubic-bezier(0.86, 0, 0.07, 1);
}

#loading-overlay::before {
    left: 0;
}

#loading-overlay::after {
    right: 0;
}

#loading-overlay.hidden {
    pointer-events: none;
    visibility: hidden; /* Hide element after transition */
    opacity: 0;
    transition: visibility 0s linear 0.8s, opacity 0.3s ease-out;
}

#loading-overlay.hidden .loading-content {
    opacity: 0;
    transform: scale(0.5) rotate(-15deg);
    transition: opacity 0.4s ease-out, transform 0.5s cubic-bezier(0.68, -0.55, 0.27, 1.55);
}

#loading-overlay.hidden::before {
    transform: translateX(-100%);
}

#loading-overlay.hidden::after {
    transform: translateX(100%);
}

.loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
    position: relative;
    z-index: 2; /* Above the curtains */
    transition: opacity 0.3s ease-out, transform 0.5s ease-out;
}

.loading-logo {
    width: 80%;
    max-width: 300px;
    height: auto;
    filter: drop-shadow(0 0 15px rgba(255, 255, 255, 0.2));
    animation: logo-pulse 2.5s infinite cubic-bezier(0.445, 0.05, 0.55, 0.95);
}

.loading-bars {
    --speed-of-animation: 1s;
    --gap: 8px;
    --first-color: #4c86f9;
    --second-color: #49a84c;
    --third-color: #f6bb02;
    --fourth-color: #e94235;
    --fifth-color: #2196f3;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 120px;
    gap: var(--gap);
    height: 80px;
}

.loading-bars span {
    width: 6px;
    height: 60px;
    border-radius: 3px;
    animation: scale var(--speed-of-animation) ease-in-out infinite;
    filter: drop-shadow(0 0 5px currentColor);
}

.loading-bars span:nth-child(1) {
    background: linear-gradient(180deg, var(--first-color), #2a6de4);
    animation-delay: -0.9s;
}
.loading-bars span:nth-child(2) {
    background: linear-gradient(180deg, var(--second-color), #2d8c30);
    animation-delay: -0.8s;
}
.loading-bars span:nth-child(3) {
    background: linear-gradient(180deg, var(--third-color), #d8a002);
    animation-delay: -0.7s;
}
.loading-bars span:nth-child(4) {
    background: linear-gradient(180deg, var(--fourth-color), #c73125);
    animation-delay: -0.6s;
}
.loading-bars span:nth-child(5) {
    background: linear-gradient(180deg, var(--fifth-color), #1177d1);
    animation-delay: -0.5s;
}

@keyframes scale {
    0%, 40%, 100% {
        transform: scaleY(0.1);
    }
    20% {
        transform: scaleY(1);
    }
}

@keyframes logo-pulse {
    0% {
        transform: scale(1);
        filter: drop-shadow(0 0 15px rgba(255, 255, 255, 0.2));
    }
    50% {
        transform: scale(1.05);
        filter: drop-shadow(0 0 25px rgba(0, 242, 234, 0.4));
    }
    100% {
        transform: scale(1);
        filter: drop-shadow(0 0 15px rgba(255, 255, 255, 0.2));
    }
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%; /* Ensure html and body take full viewport height */
    overflow: hidden; /* Prevent overall page scrollbar */
}

body {
    background-color: var(--bg-charcoal-dark);
    color: var(--text-primary);
    font-family: var(--font-family);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
}

.site-header {
    background-color: #1a1a1a;
    padding: 1rem 2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    border-bottom: 2px solid var(--neon-teal);
}

.site-title {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--neon-teal);
    text-shadow: 0 0 5px var(--neon-teal), 0 0 10px var(--neon-teal), 0 0 20px rgba(0, 242, 234, 0.5);
}

.site-logo {
    height: 50px;
    object-fit: contain;
}

#admin-login-btn {
    position: absolute;
    top: 50%;
    right: 2rem;
    transform: translateY(-50%);
    background-color: var(--bg-charcoal-light);
    color: var(--neon-teal);
    border: 1px solid var(--neon-teal);
    border-radius: var(--border-radius-control);
    padding: 0.5rem 1rem;
    cursor: pointer;
    transition: background-color var(--transition-speed), box-shadow var(--transition-speed);
}

#admin-login-btn:hover {
    background-color: var(--neon-teal);
    color: var(--bg-charcoal-dark);
    box-shadow: 0 0 8px var(--neon-teal);
}

.site-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 1600px;
    width: 100%;
    margin: 0 auto;
    overflow-y: auto; /* Allow content inside to scroll */
}

.main-content {
    padding: 2rem;
    flex: 1;
    width: 100%;
    margin: 0 auto;
}

.controls {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1.5rem;
    background-color: var(--bg-charcoal-light);
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius-card);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.search-container {
    position: relative;
    display: flex;
    align-items: center;
    flex-grow: 1;
    min-width: 250px;
}

.search-container .bi-search {
    position: absolute;
    left: 1rem;
    color: var(--text-secondary);
}

#search-box, .filter-container select {
    background-color: var(--bg-charcoal-dark);
    border: 1px solid #333;
    color: var(--text-primary);
    border-radius: var(--border-radius-control);
    font-family: var(--font-family);
    font-size: 1rem;
    padding: 0.75rem 1rem;
    transition: all var(--transition-speed) ease;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
}

#search-box {
    padding-left: 3rem;
    width: 100%;
}

#search-box:focus, .filter-container select:focus {
    outline: none;
    border-color: var(--neon-teal);
    box-shadow: 0 0 8px var(--neon-teal), inset 0 2px 4px rgba(0,0,0,0.2);
}

#search-box:hover, .filter-container select:hover {
    transform: translateY(-2px);
}

.filter-container {
    display: flex;
    gap: 0.75rem;
    flex-shrink: 0;
}

.filter-btn {
    background-color: var(--bg-charcoal-dark);
    border: 1px solid #333;
    color: var(--text-secondary);
    border-radius: var(--border-radius-control);
    padding: 0.75rem 1.2rem;
    font-family: var(--font-family);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-speed) ease;
}

.filter-btn:hover {
    color: var(--text-primary);
    border-color: #555;
    transform: translateY(-2px);
}

.filter-btn.active {
    background-color: var(--neon-teal);
    color: var(--bg-charcoal-dark);
    border-color: var(--neon-teal);
    box-shadow: 0 0 8px var(--neon-teal);
}

.section-title {
    margin-top: 3rem;
    margin-bottom: 1.5rem;
    font-size: 1.8rem;
    color: var(--neon-green);
    border-bottom: 2px solid #333;
    padding-bottom: 0.5rem;
}

.user-games-footer-text {
    margin-top: 1.5rem;
    text-align: center;
    color: var(--text-secondary);
    font-style: italic;
    font-size: 0.95rem;
    padding-top: 1rem;
    border-top: 1px dashed #333;
}

.game-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(135px, 1fr));
    gap: 1.5rem;
}

.game-card {
    background-color: var(--bg-charcoal-light);
    border-radius: var(--border-radius-card);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    position: relative;
    transition: transform var(--transition-speed) ease, box-shadow var(--transition-speed) ease;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem;
    text-align: center;
    height: 240px; /* Fixed height to ensure all cards in the grid are the same height */
    justify-content: flex-start; /* Align content to the top within the fixed height */
}

.game-card:hover {
    transform: scale(1.05);
    box-shadow: 0 8px 30px rgba(0, 242, 234, 0.2);
}

.game-card__icon-wrapper {
    position: relative;
    width: 80px;
    height: 80px;
    margin-bottom: 1rem;
    cursor: pointer;
}

.game-card__icon {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 12px;
}

.game-card__image {
    width: 100%;
    height: 140px;
    object-fit: cover;
}

.game-card__content {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.game-card__title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    word-wrap: break-word; /* Ensure long words break */
    /* Limit title to 2 lines, show ellipsis if longer */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;  
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3; /* Explicit line height for consistent height calculation */
    min-height: calc(1.1rem * 1.3 * 2); /* Reserve space for 2 lines of text */
}

.game-card__description {
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;  
    overflow: hidden;
    text-overflow: ellipsis;
    /* Ensure description has enough space for 3 lines, show ellipsis if longer */
    min-height: calc(0.8rem * 1.6 * 3); /* Reserve space for 3 lines of text */
    line-height: 1.6; /* Explicit line height for consistent height calculation */
}

.game-card__fav-icon {
    position: absolute;
    top: -4px;
    right: -4px;
    font-size: 1.25rem;
    color: var(--neon-green);
    background-color: rgba(30, 30, 30, 0.9);
    border-radius: 50%;
    padding: 0.25rem;
    line-height: 1;
    transition: transform var(--transition-speed);
    z-index: 2;
}

.game-card__fav-icon:hover {
    transform: scale(1.2);
}

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 2rem; /* Reduced vertical padding */
    margin-top: 3rem;
}

.pagination button {
    background-color: var(--bg-charcoal-light);
    border: 1px solid #333;
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-speed) ease;
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

.pagination button:hover {
    background-color: #333;
    transform: translateY(-3px);
}

.pagination button.active {
    background-color: var(--neon-teal);
    color: var(--bg-charcoal-dark);
    border-color: var(--neon-teal);
    box-shadow: 0 0 8px var(--neon-teal);
}

.pagination button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Game Viewer */
.game-viewer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.95);
    z-index: 1001;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.game-viewer__content {
    background-color: var(--bg-charcoal-light);
    border: 2px solid var(--neon-teal);
    border-radius: var(--border-radius-card);
    width: 100%;
    max-width: 1400px;
    height: 95vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 30px rgba(0, 242, 234, 0.3);
    overflow: hidden;
}

.game-viewer__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #333;
    flex-shrink: 0;
}

.game-viewer__header h2 {
    font-size: 1.5rem;
    color: var(--neon-teal);
}

.game-viewer__main {
    flex-grow: 1;
    display: flex;
    position: relative;
    overflow: hidden;
}

.game-viewer__iframe-container {
    flex-grow: 1;
    background-color: #000;
    width: 100%;
    height: 100%;
    display: flex; /* Added for centering iframe content if smaller */
    justify-content: center;
    align-items: center;
}

#game-viewer-iframe {
    width: 100%;
    height: 100%;
    border: none;
}

.game-viewer__instructions-panel {
    position: absolute;
    top: 1rem;
    left: 1rem;
    width: 300px;
    max-height: calc(100% - 2rem);
    background-color: rgba(30, 30, 30, 0.95);
    border: 1px solid #444;
    border-radius: var(--border-radius-control);
    padding: 1rem;
    overflow-y: auto;
    z-index: 10;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
}

.game-viewer__instructions-panel h3 {
    color: var(--neon-green);
    margin-bottom: 0.75rem;
    border-bottom: 1px solid #333;
    padding-bottom: 0.5rem;
}

.game-viewer__instructions-panel p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-wrap: break-word;
}

.game-viewer__footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    border-top: 1px solid #333;
    flex-shrink: 0;
    background-color: var(--bg-charcoal-light);
}

.game-viewer__footer h2 {
    font-size: 1.5rem;
    color: var(--neon-teal);
    flex-grow: 1;
    text-align: center;
    margin: 0 1rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.game-viewer__footer-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.game-viewer__footer-controls button,
.game-viewer__footer-controls a {
    background-color: var(--bg-charcoal-dark);
    border: 1px solid #333;
    color: var(--text-primary);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    text-decoration: none;
    transition: all var(--transition-speed);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.game-viewer__footer-controls button:hover,
.game-viewer__footer-controls a:hover {
    border-color: var(--neon-teal);
    color: var(--neon-teal);
    transform: translateY(-2px);
}

.game-viewer__version-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

/* New version buttons */
.game-version-btn {
    background-color: var(--bg-charcoal-dark);
    border: 1px solid #333;
    color: var(--text-primary);
    padding: 0.5rem 0.8rem; /* Adjusted padding for text */
    border-radius: var(--border-radius-control); /* Use control radius for rectangular shape */
    cursor: pointer;
    text-decoration: none;
    transition: all var(--transition-speed);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem; /* Smaller font for version text */
    white-space: nowrap; /* Prevent text wrapping */
    min-width: 80px; /* Ensure buttons have consistent width */
    height: 40px; /* Match height of other circular buttons */
}

.game-version-btn:hover {
    border-color: var(--neon-teal);
    color: var(--neon-teal);
    transform: translateY(-2px);
}

/* Add styling for active version button */
.game-version-btn.active-version-btn {
    background-color: var(--neon-teal);
    color: var(--bg-charcoal-dark);
    border-color: var(--neon-teal);
    box-shadow: 0 0 8px var(--neon-teal);
}

#game-viewer-close-btn {
    font-size: 2rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 0 0.5rem;
    line-height: 1;
}

#game-viewer-close-btn:hover {
    color: var(--accent-red);
    transform: scale(1.1) rotate(90deg);
}

.game-editor {
    padding: 1.5rem;
    background-color: #1a1a1a;
    border-top: 1px solid #333;
    flex-shrink: 0;
}

.game-editor h3 {
    margin-bottom: 1rem;
    color: var(--neon-green);
}

#edit-game-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

#edit-game-form input, #edit-game-form textarea {
    background-color: var(--bg-charcoal-dark);
    border: 1px solid #333;
    color: var(--text-primary);
    border-radius: var(--border-radius-control);
    padding: 0.5rem 0.75rem;
    font-family: var(--font-family);
    font-size: 0.9rem;
}

#edit-game-form input:focus, #edit-game-form textarea:focus {
    outline: none;
    border-color: var(--neon-green);
    box-shadow: 0 0 5px var(--neon-green);
}

.game-editor__buttons {
    display: flex;
    gap: 1rem;
    margin-top: 0.5rem;
}

.game-editor__buttons button {
    padding: 0.6rem 1.2rem;
    border-radius: var(--border-radius-control);
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-speed);
}

.game-editor__buttons button[type="submit"] {
    background-color: var(--accent-green);
    color: var(--bg-charcoal-dark);
}

.game-editor__buttons button[type="button"] {
    background-color: #444;
    color: var(--text-primary);
}

.hidden {
    display: none !important; /* Use !important to ensure it overrides other display properties */
}

/* Splash Screen Overlay */
.splash-screen-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-charcoal-dark);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    opacity: 1;
    transition: opacity 0.5s ease-out;
}

.splash-screen-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.splash-image {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
}

/* Game Description Tooltip */
.game-description-tooltip {
    position: fixed;
    background-color: rgba(30, 30, 30, 0.95); /* Semi-transparent dark background */
    border: 1px solid var(--neon-teal);
    border-radius: var(--border-radius-control);
    padding: 1rem;
    max-width: 300px;
    z-index: 1000; /* Below game viewer, above general content */
    opacity: 0;
    visibility: hidden; /* Use visibility for better transition and hiding */
    transition: opacity 0.3s ease, visibility 0.3s ease;
    pointer-events: none; /* Allows clicks to pass through to elements beneath */
    box-shadow: 0 0 15px rgba(0, 242, 234, 0.2);
}

.game-description-tooltip.visible {
    opacity: 1;
    visibility: visible;
}

.game-description-tooltip h3 {
    color: var(--neon-green);
    margin-bottom: 0.5rem;
    font-size: 1.2rem;
    border-bottom: 1px solid #444;
    padding-bottom: 0.3rem;
}

.game-description-tooltip p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    white-space: pre-wrap; /* Preserve line breaks in description */
    word-wrap: break-word; /* Break long words */
}

.game-description-tooltip p:last-child {
    margin-bottom: 0;
}

.no-results-message {
    text-align: center;
    color: var(--text-secondary);
    font-size: 1.1rem;
    margin-top: 2rem;
    grid-column: 1 / -1; /* Make it span all columns in the grid */
}

/* Responsive Design */
@media (max-width: 768px) {
    .site-logo {
        height: 40px;
    }
    .site-title {
        font-size: 2rem;
    }
    .main-content {
        padding: 1.5rem;
        flex-grow: 1;
    }
    .controls {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
        padding: 1rem;
    }
    #search-box {
        min-width: unset;
        width: 100%;
    }
    .filter-container {
        justify-content: center;
    }

    .game-viewer__footer {
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.75rem 1rem;
    }

    .game-viewer__footer h2 {
        font-size: 1.2rem;
        margin-top: 0.5rem;
        margin-bottom: 0.5rem;
    }

    .game-viewer__footer-controls {
        justify-content: center;
        width: 100%;
    }
}

@media (max-width: 480px) {
    .site-header {
        padding: 1rem;
        flex-direction: column;
        gap: 0.5rem;
    }
    #admin-login-btn {
        position: static;
        transform: none;
        margin-top: 0.5rem;
        display: block;
        width: 100%;
        text-align: center;
    }
    .game-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 1rem;
    }
}